package com.yiwu.common.domain.mapper;


import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yiwu.common.domain.dto.ProductDTO;
import com.yiwu.common.domain.entity.Products;
import org.apache.logging.log4j.util.Strings;

import java.time.LocalDate;
import java.util.Objects;

/**
* @author 咏鹅
* @description 针对表【Products】的数据库操作Mapper
* @createDate 2024-05-18 21:09:40
* @Entity generator.domain.Products
*/
public interface ProductsMapper extends BaseMapper<Products> {

    ProductDTO selectProductDetailsById(String productId);

    default Page<Products> selectPageProductList(Long current, Long size,Long userId, String description,Integer categoryId,Integer pstatus,LocalDate startDate, LocalDate endDate){
        Page<Products> page =new Page<>(current,size);

        LambdaQueryWrapper<Products> wrapper = Wrappers.<Products>lambdaQuery()
                .like(Strings.isNotBlank(description),Products::getDescription,description)
                .eq(ObjectUtil.isNotEmpty(pstatus),Products::getPstatus,pstatus)
                .eq(ObjectUtil.isNotEmpty(userId),Products::getSellerId,userId)
                .eq(ObjectUtil.isNotEmpty(categoryId) && categoryId != 0,Products::getCategoryId,categoryId)
                .ge(Objects.nonNull(startDate),Products::getCreatedAt,startDate)
                .le(Objects.nonNull(endDate),Products::getCreatedAt,endDate)
                .orderByDesc(Products::getCreatedAt);


        return selectPage(page,wrapper);
    }
}




